const express = require('express');
const app = express();
const axios = require('axios');

// 中间件
app.use(function (req,res,next){
	res.header('Access-Control-Allow-Origin', 'http://localhost:8080');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');  // RESTful-API
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    res.header('Access-Control-Allow-Credentials','true');
	next();
});

app.get('/list',(req,res) => {
	res.send({
		success:true,
		data: [1,2,3]
	})
})

app.post('/users',(req,res) => {
	res.send({
		success:true,
		data: ['leo']
	})
})

app.get('/smartisan',(req,res) => {

	axios('https://www.smartisan.com/product/shop_categories').then(({data}) => {
		res.json({
			success:true,
			data
		})
	})
	
})


// 测试接口的工具 postMan
// 自动重启应用 supervisor app.js  npm i -g supervisor   pm2

app.listen(3001);